package com.fzfnn.scrapbook.controller;
import com.fzfnn.scrapbook.service.JournalCommonService;
import com.fzfnn.scrapbook.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/journal/common")
@Tag(name = "用户公共接口", description = "公共操作手账相关接口")
public class JournalCommonController {
    @Autowired
    private JournalCommonService journalCommonService;


    @GetMapping("/getall")
    @Operation(summary = "获取手账(包括非公开)")
    public R getJournal() {
        return journalCommonService.getJournal();
    }

    @GetMapping("/getallinpublic")
    @Operation(summary = "直接获取所有手账(仅公开)")
    public R getJournalInPublic() {
        return journalCommonService.getJournalbyPublic();
    }

    @GetMapping("/getallinpublicbypaging")
    @Operation(summary = "通过分页获取手帐(仅公开&普通推送)")
    public R getJournalInPublicByPage(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return journalCommonService.getPublicJournalsByPage(page, size);
    }

    @GetMapping("/getbyid/{journalId}")
    @Operation(summary = "获取指定id手账（不包括非公开）")
    public R getJournalbyId(@PathVariable Integer journalId,
                           @RequestHeader("Authorization") String token) {
        return journalCommonService.getJournalbyId(journalId, token);
    }

    @GetMapping("/followed")
    @Operation(summary = "获取关注用户发布的手账")
    public R getFollowedJournals(@RequestHeader("Authorization") String token) {
        return journalCommonService.getJournalsFromFollowedUsers(token);
    }

    @GetMapping("/getallinpublicbypagingwithdiy")
    @Operation(summary = "通过分页获取手帐(仅公开&个性化推荐)")
    public R getRecommendedJournalsByPage(@RequestHeader("Authorization") String token,
                                          @RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int size) {
        return journalCommonService.getRecommendedJournalsByPage(token, page, size);
    }



}
